"""
商品品牌销量

"""
from django.http import JsonResponse
from django.shortcuts import render, redirect
from workDjango import models


# 可视化部分
def show_brand(request):
    return render(request, 'work03.html')


# 1.1.品牌销售详情可视化
def goods_sale_brand_show(request):
    y_data = []
    x_data = []
    y2_data = []
    y3_data = []
    y4_data = []
    data = models.BrandSummary.objects.all()

    for i in data:
        x_data.append(i.brand)
        y_data.append(i.total_sales_volume)
        y2_data.append(i.avg_price)
        y3_data.append(i.avg_rating)
        y4_data.append(i.avg_sales_volume_per_product)

    x_list = x_data
    y_list = [
        {'name': '销量',
         'type': 'bar',  # 设置图像类别
         'data': y_data}
    ]
    y2_list = [
        {'name': '平均价格',
         'type': 'line',  # 设置图像类别
         'data': y2_data}
    ]
    y3_list = [
        {'name': '平均评分',
         'type': 'line',  # 设置图像类别
         'data': y3_data}
    ]
    y4_list = [
        {'name': '平均销量',
         'type': 'line',  # 设置图像类别
         'data': y4_data}
    ]
    legend = []
    result = {
        "status": True,
        "data": {
            "x_list": x_list,
            "y_list": y_list,
            "y2_list": y2_list,
            "y3_list": y3_list,
            "y4_list": y4_list
        }
    }
    return JsonResponse(result)
